<template>
  <div class="user-profile">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>个人信息</span>
        </div>
      </template>
      
      <el-form :model="userInfo" label-width="100px">
        <el-form-item label="用户名">
          <el-input v-model="userInfo.username" disabled />
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="userInfo.realName" />
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="userInfo.email" />
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="userInfo.phone" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSave">保存</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    
    <!-- 修改密码对话框 -->
    <change-password-dialog
      v-model="showPasswordDialog"
      @success="handlePasswordChange"
    />
    
    <el-card class="security-card">
      <template #header>
        <div class="card-header">
          <span>安全设置</span>
        </div>
      </template>
      
      <div class="security-item">
        <span>账户密码</span>
        <el-button type="text" @click="showPasswordDialog = true">修改</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import ChangePasswordDialog from '@/components/ChangePasswordDialog.vue'

export default {
  name: 'UserProfile',
  components: {
    ChangePasswordDialog
  },
  setup() {
    const userInfo = ref({
      username: 'admin',
      realName: '管理员',
      email: 'admin@example.com',
      phone: '13800138000'
    })
    
    const showPasswordDialog = ref(false)
    
    const handleSave = () => {
      ElMessage.success('个人信息保存成功')
    }
    
    const handlePasswordChange = () => {
      ElMessage.success('密码修改成功')
      showPasswordDialog.value = false
    }
    
    return {
      userInfo,
      showPasswordDialog,
      handleSave,
      handlePasswordChange
    }
  }
}
</script>

<style scoped>
.user-profile {
  padding: 20px;
}

.card-header {
  font-size: 16px;
  font-weight: 500;
}

.security-card {
  margin-top: 20px;
}

.security-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #ebeef5;
}

.security-item:last-child {
  border-bottom: none;
}
</style>